<%--
  Created by IntelliJ IDEA.
  User: FENG1
  Date: 2022/5/3
  Time: 17:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%>
<html>
<head>
    <base href="<%=basePath%>">
    <head>
        <title>权限分配</title>
        <link rel="stylesheet" href="static/component/pear/css/pear.css" />
        <%--<link rel="stylesheet" href="static/css/layui.css">--%>
        <style>
            .layui-tree-set{
                margin:20px 0;
            }
            body{
                padding-bottom: 40px;
            }
        </style>
    </head>
<body>
<form class="layui-form layui-form-pane" action="">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>
            ${role.rName}
           <%-- <input type="hidden" value="${role.permissionId}" name="perId">--%>
            <input type="hidden" value="${role.rid}" name="rid">
        </legend>
    </fieldset>
    <div id="test1" style="line-height: 40px;margin-left:30px"></div>
    <div class="bottom" style="position:fixed">
        <div class="button-container">
            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="static/component/layui/layui.js"></script>
<script src="static/component/pear/pear.js"></script>
<%--<script src="static/js/layui.js"></script>--%>
<script>
    layui.use(['tree', 'util','jquery','form'], function() {
        var admin = layui.admin;
        var tree = layui.tree,
            layer = layui.layer,
            util = layui.util;
        let $ = layui.jquery;
        let form = layui.form;
         //let perId = $("[name = perId]").val();
         //将字符串转为数组
        /*var arr = perId.split(',');*/
        var arr =${perids};
        $.post('permission/getQuery',{},function(res){
            tree.render({
                elem: '#test1',
                showCheckbox:true,
                spread:true,
                data:res,
                id: 'demoId1',
                click: function(obj){
                    console.log(obj.state);
                    var data = obj.data;  //获取当前点击的节点数据
                    console.log(data);
                }
            })
            tree.setChecked('demoId1', arr); //勾选指定节点
        },'json')



        //进行权限分配
        form.on('submit(user-save)', function(obj){
            let arrperId =new Array();
            let id = $("[name=rid]").val();
            $('input:checkbox:checked').each(function(i){
                arrperId[i]=$(this).val();
            });
            alert(typeof id);
            // perId=perId.substring(0,perId.length-1);//减去最后一位  逗号,
           $.post('permission/updatePerId',{arrperId:arrperId,idStr:id},function(result){
                if(result.success){
                    layer.msg(result.msg,{icon:1,time:1000},function(){
                        window.close();
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.parent.location.reload(); // 父页面刷新
                        parent.layui.table.reload("user-table");
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:1000});
                }
            })
        })
    })
</script>
</body>
</html>